package com.it.testDemo;

import com.alibaba.druid.sql.visitor.functions.Now;
import com.it.config.SpringConfig;
import com.it.service.UserService;
import jdk.swing.interop.SwingInterOpUtils;
import org.dom4j.*;
import org.dom4j.dom.DOMComment;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;



public class ConfigTest {
    private String a, b, c;
    public String xml ="<FYMX><FYMXITEM IID='21000001' CJZD='2103000001' CZYH='2100351' CYLH='W21000277' CXM='漆梓轩' CXB='男' CNL='1岁10月' IDYLB='13' CDYLB='本地居民医保' CSFXM='浅表器官彩色多普勒超声检查(关节)' IZTJZ='0' IZYKS='1002' CZYKS='儿科' IZYBQ='11' CZYBQ='儿科' IZYYS='1953' CZYYS='段新' MJE='90.0000' MSJ='90.0000' DRQ='2021-03-04T10:18:54.120' CBZ='' CDW='次 ' ISL='1.00' MDJ='90.0000' CSFXMBM='220301002.09' CSFR='管理员' FBL='1.0000' ITXBJ='0' CTXR='' CQMYS='' CDJH='' IYBBJ='0' CZXKSBM='01006' CSSBH='' CSFRGH='0100' BICUFY='0' CYJZD='' CCWTJ='B超' CFYTJ='超声检查费' ILB='0' BTF='0' CZXKSMC='B超室' CZHXMBM='CS001' CZHXMMC='小儿髋关节彩超' CKDKSBM='01002' CKDKSMC='儿科' CXSE='' DDYSJ='2021-03-04T10:18:54.120' DYRQ='1899-12-30T00:00:00' CZXRBM='' CZXRMC='' CLJBH='' CZRHSBM='1922' CZRHSMC='李静' IGCYS='1953' CGCYS='段新' CBRCW='030' CBJFYBZ='' CTXM='' CYWFYBZ='' CSBXX=''/></FYMX>	";

    @Test
    public void test() {
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserService userService = context.getBean("userService", UserService.class);
        System.out.println(userService);
        String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        System.out.println(format);
        userService.add();
        System.out.println("*****************-|");
        Document document = null;
        try {
            document = DocumentHelper.parseText(xml);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        if (document.selectSingleNode("ZYZ/ZYX.1") != null) {
            System.out.println(document.selectSingleNode("ZYZ/ZYX.1").getText());
        }

        Node node = document.selectSingleNode("ZYZ/ZYX.1");
        System.out.println(node.asXML());
        System.out.println(node.selectSingleNode("aa").getText());
        //input = document.selectNodes("//DataSet/row");
        int count = 0;
        System.out.println("%%%%%%%%%%%%%%%%%%");
        int j = 3;
        for (int i = 0; i < j; i++) {
            switch (i) {
                case 0:
                    System.out.println("输出i=" + i);
                    break;
                case 1:
                    System.out.println("输出i=" + i);
                    break;
                case 2:
                    System.out.println("输出i=" + i);
                    break;
            }
        }
        // DecimalFormat df = new DecimalFormat("0.00");//输出"00.12"


//        for (Iterator<Node> iter = input.iterator(); iter.hasNext();) {
//            Element MZZDNode = (Element) iter.next();
//            Iterator<Element> it = MZZDNode.elementIterator();
//            while (it.hasNext()) {
//                // 获取某个子节点对象
//                Element e = it.next();
//                // 对子节点进行遍历
//                System.out.println(e.asXML());
//                if (e.getNodeType()==Node.ELEMENT_NODE){
//
//                }
//            }
//
//
//           // System.out.println(next.asXML());
//        }

        String testString = "123abcdefg";
        System.out.println(testString.charAt(testString.length() - 1));
        List list = new LinkedList();
        if (list == null || list.isEmpty()) {
            System.out.println("空空如也");
        } else {
            System.out.println(list.get(0));
        }
        Float formatfloat = formatfloat("0.000", "3.141592678");
        System.out.println("掉方法后=" + formatfloat);
        String a = "123456bfag";
        System.out.println("%%%" + a.indexOf("bf"));
        System.out.println(a.substring(0 - 1, 6));
        System.out.println("%%%%%%%%%%%%%%%%%%");
//        Element element = getElement(input);
//        int index=1;
//        for (Iterator<Element> it = element.elementIterator("PSN_NAME"); it.hasNext();) {
//            System.out.println("#######");
//
//            Element foo = it.next();
//            System.out.println("index="+index);
//            System.out.println("MZZDNODE"+foo.selectSingleNode("a").getText());
//            System.out.println("MZZDNODE"+foo.selectSingleNode("PSN_NAME").getText());
//            index=index+1;
//            System.out.println(foo.asXML());
//
//         //   System.out.println(foo);
        // do something
    }


    // user_code= element.selectSingleNode("PSN_NAME");
    //System.out.println(user_code.asXML());


    // System.out.println(input);
    //  getElement();
//        System.out.println("-|********************");
    // }
    @Test
    public void test2() throws DocumentException {
        String str = "1=2|3=7|5=6";
        String[] list1 = str.split("\\|");
        List<String> list = new ArrayList<>();
        for (String arr : list1
        ) {
            String[] split = arr.split("=");
            for (String res : split
            ) {
                list.add(res);
            }
        }
        for (int i = 0; i < list.size() - 1; i++) {
            System.out.println(list.get(i));
        }

        fun("1", "2", "3");
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        String format = new SimpleDateFormat("YYYY-mm-dd").format(new Date());
        System.out.println(format);
    }

    private Element getElement(List<Node> ListNode) {
        Node node = null;
        for (int i = 0; i < ListNode.size(); ) {
            node = ListNode.get(i);
            while (node != null) {
                if (node instanceof Element) {
                    return (Element) node;
                }
                i++;
            }
//           if (node instanceof Element){
//            return (Element)node;
//           }
        }
        return (Element) node;
    }

    public Float formatfloat(String pattern, String value) {
        DecimalFormat dformate = new DecimalFormat(pattern);
        float paraseValue = Float.parseFloat(value);
        Float result = Float.parseFloat(dformate.format(paraseValue));
        return result;
    }


    public void fun(String a, String b, String c) {
        this.a = a;
        this.b = b;
        this.c = c;
        if (true) {
            this.a = "aaa";
            this.b = "bbb";
            this.c = "ccc";
        }
        System.out.println("a=======》" + a);
        System.out.println("b=======>" + b);
        System.out.println("c========>" + c);
        List<Integer> ba = new LinkedList<>();
        ba.add(1);
        ba.add(2);
        ba.add(10);
        System.out.println(ba.size() + "个");


    }

    @Test
    public void test4() throws DocumentException {
        int index = 0;
        String a = "", b = "", c = "", d = "", f = "";

        Document document = DocumentHelper.parseText(xml);
        // Element rootElement = (Element)document.selectNodes("//row");// 获得文档对象的根节点
        List<Node> listElement = document.selectNodes("FYMX/FYMXITEM");
        for (Node e1 : listElement) {// 遍历所有的子节点
            //     List<Element> element2 = e1.elements();//

            Element elements = (Element) e1;
            List<Element> elements1 = elements.elements();
//        e1    if (element.attributeValue("a") != null || element.attributeValue("a") != "") {
//                System.out.println(a);
//            }


                a = elements.attributeValue("CJZD");// 得到当前节点的属性对象
                b = elements.attributeValue("CZYH");
                c = elements.attributeValue("CYLH");
                d = elements.attributeValue("CNL");

                if (a!=null){
                    System.out.println("a:"+a+"---");
                }
                if (b!=null){
                    System.out.println("b:"+b+"---");
                }
                if (c!=null){
                    System.out.println("c:"+c+"---");
                }
                if (d!=null){
                    System.out.println("d:"+d+"---");
                }






                // 将节点信息输出


        }

    }

    @Test
    public void test1() {
        String Tmp="<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"yes\"?>";
        String S="";
        if (Tmp.indexOf("?>")==-1){
            Tmp="<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"yes\"?>"+Tmp;

        }else {
            System.out.println(Tmp.indexOf("?>"));
            System.out.println(Tmp.charAt(54));
            S= Tmp.substring(0,Tmp.indexOf("?>")+2);
            System.out.println(S);
        }

    }


}

